home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / COMMADIO / KERMIT1.LZH / PCKFIX.ASM < prev    next >
Assembly Source File  |  1980-01-01  |  6KB  |  212 lines

  1. ; Program to convert KERMIT.EXE to all printable characters.  For each
  2. ; byte of the file, convert to two characters in the range 20 to 2F. 
  3. ; This is done by adding a space to each nibble.  The file KERMIT.FIX
  4. ; is created with 64 characters per line.
  5. ;
  6. ; Daphne Tzoar
  7. ; 1/83
  8. ; Columbia University Center for Computing Activities
  9.  
  10. DOS     EQU     21H
  11.  
  12. STACK   SEGMENT PARA STACK 'STACK'
  13.         DW      100 DUP (0)
  14. STK     EQU     THIS WORD
  15. STACK   ENDS    
  16.  
  17. DATAS   SEGMENT PARA PUBLIC 'DATAS'
  18. buff    db      80H DUP(0)
  19. bufone  db      80H DUP(0)
  20. buftwo  db      80H DUP(0)
  21. fcbold  db      25H DUP(0)
  22. fcbnew  db      25H DUP(0)
  23. oldstk  dw      ?
  24. kold    db      'KERMIT  EXE$'
  25. knew    db      'KERMIT  FIX$'
  26. chrcnt  db      0
  27. datcnt  db      0
  28. eoflag  db      0
  29. crflg   db      0
  30. cnt     db      0
  31. DATAS   ENDS
  32.  
  33. MAIN    SEGMENT PARA PUBLIC 'MAIN'
  34. START   PROC    FAR
  35.         ASSUME CS:MAIN,DS:DATAS,SS:STACK,ES:NOTHING
  36.  
  37.         push ds                         ; Initialization
  38.         sub ax,ax
  39.         push ax
  40.  
  41.         mov ax,datas
  42.         mov ds,ax
  43.         sub ax,ax
  44.  
  45.         mov oldstk,sp
  46.  
  47.         mov ah,1AH                      ; Use my own DTA
  48.         mov dx,offset buff
  49.         int dos
  50.         call one
  51.         mov sp,oldstk
  52.         ret
  53. START   ENDP
  54.         
  55. ONE     PROC    NEAR
  56.         mov bx,offset fcbold
  57.         mov ah,0
  58.         mov [bx],ah                     ; Use default drive.
  59.         inc bx
  60.         mov di,offset kold              ; Get name of original file.
  61. kerm3:  mov ah,[di]
  62.         cmp ah,'$'                      ; Got all the data?
  63.         je kerm4
  64.         mov [bx],ah
  65.         inc di
  66.         inc bx
  67.         jmp kerm3
  68. kerm4:  mov bx,offset fcbnew
  69.         mov ah,0
  70.         mov [bx],ah
  71.         inc bx
  72.         mov di,offset knew
  73. kerm5:  mov ah,[di]
  74.         cmp ah,'$'
  75.         je kerm6
  76.         mov [bx],ah
  77.         inc di
  78.         inc bx
  79.         jmp kerm5
  80.  
  81. kerm6:  mov ax,0
  82.         mov bx,offset fcbold+0CH
  83.         mov [bx],ax                     ; Zero current block number.
  84.         mov bx,offset fcbold+0EH
  85.         mov [bx],ax                     ; Lrecl.
  86.         mov bx,offset fcbold+20H
  87.         mov [bx],ah                     ; Current record (of block).
  88.         inc bx
  89.         mov [bx],ax                     ; Current record (of file).
  90.         mov bx,offset fcbold+23H
  91.         mov [bx],ax
  92.         mov ah,0FH                      ; Open file.
  93.         mov dx,offset fcbold
  94.         int dos
  95.  
  96.         mov ax,0
  97.         mov bx,offset fcbnew+0CH
  98.         mov [bx],ax                     ; Zero current block number.
  99.         mov bx,offset fcbnew+0EH
  100.         mov [bx],ax                     ; Lrecl.
  101.         mov bx,offset fcbnew+20H
  102.         mov [bx],ah                     ; Current record (of block).
  103.         inc bx
  104.         mov [bx],ax                     ; Current record (of file).
  105.         mov bx,offset fcbnew+23H
  106.         mov [bx],ax
  107.         mov ah,16H                      ; Create file.
  108.         mov dx,offset fcbnew
  109.         int dos
  110.         mov eoflag,0                    ; Not end-of-file yet.
  111.         mov datcnt,0                    ; Chars in write-out buffer.
  112.         mov chrcnt,0                    ; Chars in read-to buffer.
  113.         mov crflg,0
  114.         mov cnt,0
  115.         mov bx,offset bufone
  116.         mov di,offset buftwo
  117.  
  118. kerm1:  cmp chrcnt,0H
  119.         jne kerm0
  120.         call inbuf                      ; Get a buffer-full.
  121.           jmp kerm9
  122.         mov ax,ds
  123.         mov es,ax                       ; Move for Dest uses ES register.
  124.         mov si,offset buff
  125.         push di
  126.         mov di,offset bufone            ; Move read-in data to bufone.
  127.         mov cx,80H
  128.         rep movs es:bufone,buff
  129.         pop di
  130.  
  131.         mov bx,offset bufone            ; Where the chars are.
  132.         mov chrcnt,80H                  ; Number of chars.
  133. kerm0:  cmp datcnt,80H
  134.         je kerm2
  135.         dec chrcnt
  136.         mov ah,[bx]                     ; Get a char.
  137.         mov ch,ah                       ; Save here.
  138.         and ah,0F0H                     ; Get high nibble.
  139.         and ch,0FH                      ; Lower nibble.
  140.         mov cl,4
  141.         shr ax,cl
  142.         add ah,' '                      ; Make printable.
  143.         mov [di],ah
  144.         inc datcnt
  145.         inc di
  146.         add ch,' '
  147.         mov [di],ch
  148.         inc datcnt
  149.         inc di
  150.         inc bx
  151.         add cnt,2
  152.         cmp cnt,40H                     ; Time to add CRLF?
  153.         jne kerm1
  154.         mov cnt,0                       ; Reset counter.
  155.         cmp datcnt,80H                  ; Have room for it?
  156.         jne kerm8                       ; Yup, we do.
  157.         mov crflg,0FFH
  158.         jmp kerm2
  159.  
  160. kerm8:  mov crflg,0
  161.         mov ax,0A0DH
  162.         mov [di],ax
  163.         inc di
  164.         inc di
  165.         add datcnt,2
  166.         jmp kerm1
  167.  
  168. kerm2:  mov ax,ds
  169.         mov es,ax                       ; Move for Dest uses ES register.
  170.         mov si,offset buftwo
  171.         mov di,offset buff
  172.         mov cx,80H
  173.         rep movs es:buff,buftwo         ; Must use BUFF for r/w to file.
  174.  
  175.         mov ah,15H                      ; Write out to file two.
  176.         mov dx,offset fcbnew
  177.         int dos
  178.         mov datcnt,0
  179.         mov di,offset buftwo            ; Start at beginning of buffer.
  180.         cmp crflg,0FFH                  ; Had our buffer filled prior to CRLF?
  181.         je kerm8                        ; Yup.
  182.         jmp kerm1                       ; Get new buffer-full.
  183.  
  184. kerm9:  mov ah,10H                      ; Close files.  
  185.         mov dx,offset fcbold
  186.         int dos
  187.         mov dx,offset fcbnew
  188.         int dos
  189.         ret
  190.  
  191. inbuf:  cmp eoflag,0                    ; End of file?
  192.         je inbuf0                       ; Nope.
  193.         ret
  194. inbuf0: mov dx,offset fcbold
  195.         mov ah,14H                      ; Read from file.
  196.         int dos
  197.         cmp al,0
  198.         je inbuf2
  199.         mov eoflag,0FFH
  200. inbuf2: jmp rskp
  201. ONE     ENDP
  202.  
  203. RSKP    PROC  NEAR
  204.         pop bp
  205.         add bp,3
  206.         push bp
  207.         ret
  208. RSKP    ENDP
  209.  
  210. MAIN    ENDS
  211.         END     START
  212.